package com.lechi.web.controller;

import com.lechi.web.common.core.controller.BaseController;
import com.lechi.web.common.core.domain.AjaxResult;
import com.lechi.web.constants.Constants;
import com.lechi.web.runner.CacheCmdParseMsg;
import com.lechi.web.service.IIotWeatherDictService;
import com.lechi.web.system.domain.IotWeatherDict;
import com.lechi.web.vo.IotWeatherDictVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;


/**
 * 气象观测业务分类及编码Controller
 *
 * @author yangguang
 */
@RestController
@RequestMapping("/iot/weather")
@RequiredArgsConstructor
public class IotWeatherDictController extends BaseController {

    private final IIotWeatherDictService iotWeatherDictService;

    private final CacheCmdParseMsg cacheCmdParseMsg;

    /**
     * 获取气象观测业务分类及编码详细信息
     *
     * @param deviceId the device id
     * @return the info
     */
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) {
        return success(iotWeatherDictService.selectIotWeatherDictById(deviceId));
    }

    /**
     * 修改气象观测业务分类及编码
     *
     * @param iotWeatherDictVo the iot weather dict vo
     * @return the ajax result
     */
//    @PreAuthorize("@ss.hasPermi('iot:dict:add')")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody IotWeatherDictVo iotWeatherDictVo) {
        IotWeatherDict iotWeatherDict = new IotWeatherDict();
        BeanUtils.copyProperties(iotWeatherDictVo, iotWeatherDict);
        cacheCmdParseMsg.run(String.valueOf(iotWeatherDictVo.getDeviceId()), Constants.WEATHER2017);
        return toAjax(iotWeatherDictService.updateIotWeatherDict(iotWeatherDict));
    }
}
